﻿Public Class FrmInfo

	Dim WithEvents Extractor As New ExifExtractor

	Sub New()
		InitializeComponent()
		With List
			.RowHeadersVisible = False
			.ColumnHeadersBorderStyle = DataGridViewHeaderBorderStyle.None
			.AllowUserToAddRows = False
			.AllowUserToOrderColumns = False
			.AllowUserToResizeRows = False
			.Columns.Add("name", "Exif etiketi")
			.Columns.Add("value", "Değer")
			.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
			.Columns(0).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
			.Columns(0).FillWeight = 40
			.Columns(0).DefaultCellStyle.ForeColor = SystemColors.GrayText
			.Columns(1).AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill
			.Columns(1).FillWeight = 60
			.GridColor = SystemColors.ButtonFace
			.BackgroundColor = SystemColors.ButtonFace
		End With
	End Sub

	Sub Open(ByVal File As String)
		'Dim Img = Images.Thumbs.Read(File)
		'Picture.Width = Picture.Height / Img.Height * Img.Width
		Picture.BackgroundImageLayout = ImageLayout.Stretch
		'Picture.BackgroundImage = Img
		Dim P = Picture.Location
		P.Offset(List.Right - Picture.Right, 0)
		Picture.Location = P
		Picture.Anchor = AnchorStyles.Top Or AnchorStyles.Right
		Extractor.File = File
		For Each Item In Extractor.Tags.Values
			List.Rows.Add(Item.Definition, "")
		Next
		Extractor.Start()
	End Sub

	Private Sub Extractor_Finished() Handles Extractor.Finished
		For Each Item In Extractor.Tags.Values
			Dim Key = Item.Definition
			Dim row = (From r As DataGridViewRow In List.Rows Where r.Cells(0).Value = Key).FirstOrDefault
			If Not row Is Nothing Then row.cells(1).Value = IsNull(Item.Value, "")
		Next
		HideShowEmpty()
	End Sub

	Sub HideShowEmpty() Handles HideEmpty.CheckedChanged
		For Each Row As DataGridViewRow In List.Rows
			Row.Visible = Trim(Row.Cells(1).Value) > "" Or Not HideEmpty.Checked
		Next
	End Sub

	Private Sub Picture_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Picture.Paint
		Dim R = Picture.ClientRectangle
		R.Width -= 1 : R.Height -= 1
		e.Graphics.DrawRectangle(Color.Black.Opacity(64).Pen, R)
	End Sub

End Class